<!-- xml version="1.0" encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>Latin Verbs</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="../classics.css" rel="stylesheet" type="text/css">
</head>

<?php

$verbs = array();
function addVerb($verb, $pres_stem, $perf_stem, $part_stem) {
	global $verbs;
	$verbs[$verb] = array('pres_stem' => $pres_stem, 'perf_stem' => $perf_stem, 'part_stem' => $part_stem);
}

addVerb('amāre', 'am', 'amāv', 'amāt');
addVerb('appellāre', 'appell', 'appellāv', 'appellāt');


$endings = array();
function addEnding($voice, $mood, $tense, $vI, $vThou, $vHe, $vWe, $vYe, $vThey) {
	global $endings;
	$endings[$voice][$mood][$tense] = array('I' => $vI, 'Thou' => $vThou, 'He' => $vHe,
		                                    'We' => $vWe, 'Ye' => $vYe, 'They' => $vThey);
}

addEnding('Act.', 'Indic.', 'Pres.', 'ō', 'ās', 'at', 'āmus', 'ātis', 'ant');
addEnding('Pass.', 'Indic.', 'Pres.', 'or', array('āris', 'āre'), 'ātur', 'āmur', 'āminī', 'antur');
addEnding('Act.', 'Subj.', 'Pres.', 'em', 'ēs', 'et', 'ēmus', 'ētis', 'ent');
addEnding('Pass.', 'Subj.', 'Pres.', 'er', array('ēris', 'ēre'), 'ētur', 'ēmur', 'ēminī', 'entur');

addEnding('Act.', 'Indic.', 'Impf.', 'ābam', 'ābās', 'ābat', 'ābāmus', 'ābātis', 'ābant');
addEnding('Pass.', 'Indic.', 'Impf.', 'ābar', array('ābāris', 'ābāre'), 'ābātur', 'ābāmur', 'ābāminī', 'ābantur');
addEnding('Act.', 'Subj.', 'Impf.', 'ārem', 'ārēs', 'āret', 'ārēmus', 'ārētis', 'ārent');
addEnding('Pass.', 'Subj.', 'Impf.', 'ārer', array('ārēris', 'ārēre'), 'ārētur', 'ārēmur', 'ārēminī', 'ārentur');

addEnding('Act.', 'Indic.', 'Fut.', 'ābō', 'ābis', 'ābit', 'ābimus', 'ābitis', 'ābunt');
addEnding('Pass.', 'Indic.', 'Fut.', 'ābor', array('āberis', 'ābere'), 'ābitur', 'ābimur', 'ābiminī', 'ābuntur');

addEnding('Act.', 'Indic.', 'Perf.', 'ī', 'istī', 'it', 'imus', 'istis', array('ērunt', 'ēre'));
addEnding('Pass.', 'Indic.', 'Perf.', 'us sum', 'us es', 'us est', 'ī sumus', 'ī estis', 'ī sunt');
addEnding('Act.', 'Subj.', 'Perf.', 'erim', 'eris', 'erit', 'erimus', 'eritis', 'erint');
addEnding('Pass.', 'Subj.', 'Perf.', 'us sim', 'us sīs', 'us sit', 'ī sīmus', 'ī sītis', 'ī sint');

addEnding('Act.', 'Indic.', 'Plup.', 'eram', 'erās', 'erat', 'erāmus', 'erātis', 'erant');
addEnding('Pass.', 'Indic.', 'Plup.', 'us eram', 'us erās', 'us erat', 'ī erāmus', 'ī erātis', 'ī erant');
addEnding('Act.', 'Subj.', 'Plup.', 'issem', 'issēs', 'isset', 'issēmus', 'issētis', 'issent');
addEnding('Pass.', 'Subj.', 'Plup.', 'us essem', 'us essēs', 'us esset', 'ī essēmus', 'ī essētis', 'ī essent');

addEnding('Act.', 'Indic.', 'Fut.Perf.', 'erō', 'eris', 'erit', 'erimus', 'eritis', 'erint');
addEnding('Pass.', 'Indic.', 'Fut.Perf.', 'us erō', 'us eris', 'us erit', 'ī erimus', 'ī eritis', 'ī erunt');

$endings['Act.']['Imper.']['Pres.']['Thou'] = 'ā';
$endings['Pass.']['Imper.']['Pres.']['Thou'] = 'āre';
$endings['Act.']['Imper.']['Pres.']['Ye'] = 'āte';
$endings['Pass.']['Imper.']['Pres.']['Ye'] = 'āminī';
$endings['Act.']['Imper.']['Fut.']['Thou'] = 'ātō';
$endings['Pass.']['Imper.']['Fut.']['Thou'] = 'ātor';
$endings['Act.']['Imper.']['Fut.']['Ye'] = 'ātōte';
$endings['Act.']['Imper.']['Fut.']['He'] = 'ātō';
$endings['Pass.']['Imper.']['Fut.']['He'] = 'ātor';
$endings['Act.']['Imper.']['Fut.']['They'] = 'antō';
$endings['Pass.']['Imper.']['Fut.']['They'] = 'antor';

$endings['Act.']['Infinitive']['Pres.'] = 'āre';
$endings['Pass.']['Infinitive']['Pres.'] = 'ārī';
$endings['Act.']['Infinitive']['Perf.'] = 'isse';
$endings['Pass.']['Infinitive']['Perf.'] = 'us esse';
$endings['Act.']['Infinitive']['Fut.'] = 'ūrus esse';
$endings['Pass.']['Infinitive']['Fut.'] = 'um īrī';

$endings['Act.']['Participle']['Pres.'] = 'āns';
$endings['Pass.']['Participle']['Perf.'] = 'us';
$endings['Act.']['Participle']['Fut.'] = 'ūrus';

$endings['Act.']['Gerund'] = 'andum';
$endings['Pass.']['Gerundive'] = 'andus';
$endings['Act.']['Supine'] = 'um';

$verb = array_rand($verbs);
$persons = array('I', 'Thou', 'He', 'We', 'Ye', 'They', 'Other');
$person = $persons[array_rand($persons)];

$n = 3;
if ($person != 'Other') {
	$vtab = "<caption>".$verb." - ".$person."</caption>\n";
	$nVoice = count($endings);
	
	$vtab = $vtab . "<tr><td></td><th colspan=".$nVoice." align=\"center\">Indic.</th>";
	$vtab = $vtab . "<th colspan=".$nVoice." align=\"center\">Subj.</th>";
	$vtab = $vtab . "<th colspan=".$nVoice." align=\"center\">Imper.</th></tr>\n";
	$tmp = '';
	foreach($endings as $voice => $vArray) {
		$tmp = $tmp . "<td align=\"center\">$voice</td>";
	}
	$vtab = $vtab."<tr><td></td>".$tmp.$tmp.$tmp."</tr>\n";
	
	foreach(array('Pres.', 'Impf.', 'Fut.', 'Perf.', 'Plup.', 'Fut.Perf.') as $tense) {

		$vtab = $vtab . "<tr><th>$tense</th>";
		foreach(array('Indic.', 'Subj.', 'Imper.') as $mood) {
			foreach($endings as $voice => $vArray) {
				$stem = $verbs[$verb]['pres_stem'];
				if ($tense == 'Perf.' || $tense == 'Plup.' || $tense == 'Fut.Perf.') {
					$stem = $verbs[$verb]['perf_stem'];
				} 
				
				if ($voice == 'Pass.' && ($tense == 'Perf.' || $tense == 'Plup.' || $tense == 'Fut.Perf.')) {
					$stem = $verbs[$verb]['part_stem'];
				}
				$vtab = $vtab . "<td align=\"center\">";
				if (isset($endings[$voice][$mood][$tense][$person])) {
					$ending = $endings[$voice][$mood][$tense][$person];
					if (is_array($ending)) {
						foreach($ending as $end) {
							$txts[] = $stem.$end;
							$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\" size=\"15\">";
						}
					} else {
						$txts[] = $stem.$ending;
						$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\" size=\"15\">";
					}
				}
				$vtab = $vtab . "</td>";
			}
		}
		$vtab = $vtab . "</tr>\n";
	}
} else {
	$n = 1;
	$vtab = "<caption>".$verb."</caption>\n";
	$tmp = '';
	foreach($endings as $voice => $vArray) {
		$tmp = $tmp . "<th align=\"center\">$voice</th>";
	}
	foreach(array('Infinitive', 'Participle') as $mood) {
		$vtab = $vtab."<tr bgcolor=\"CadetBlue\"><th>$mood</th>$tmp</tr>\n";
		foreach(array('Pres.', 'Fut.', 'Perf.') as $tense) {

			$vtab = $vtab."<tr><th>$tense</th>";
			foreach(array('Act.', 'Pass.') as $voice) {
				$stem = $verbs[$verb]['pres_stem'];
				if ($tense == 'Fut.' || $tense == 'Perf.') {
					$stem = $verbs[$verb]['part_stem'];
				}
				if ($mood == 'Infinitive' && $tense == 'Perf.' && $voice == 'Act.') {
					$stem = $verbs[$verb]['perf_stem'];
				}
				$vtab = $vtab."<td align=\"center\">";
				if (isset($endings[$voice][$mood][$tense])) {
					$ending = $endings[$voice][$mood][$tense];
					if (is_array($ending)) {
						foreach($ending as $ed) {
							$txts[] = $stem.$ed;
							$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
						}
					} else {
						$txts[] = $stem.$ending;
						$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
					}
				}
				$vtab = $vtab."</td>";
			}
			$vtab = $vtab."</tr>\n";
		}
	}
	$vtab = $vtab."<tr bgcolor=\"CadetBlue\"><td colspan=3></td></tr>\n";
	foreach(array('Gerund', 'Gerundive', 'Supine') as $type) {
		$stem = $verbs[$verb]['pres_stem'];
		if ($type == 'Supine') {
			$stem = $verbs[$verb]['part_stem'];
		}
		$vtab = $vtab."<tr><th bgcolor=\"CadetBlue\">$type</th>";
		foreach(array('Act.', 'Pass.') as $voice) {
			$vtab = $vtab."<td align=\"center\">";
			if (isset($endings[$voice][$type])) {
				$ending = $endings[$voice][$type];
				if (is_array($ending)) {
					foreach($ending as $ed) {
						$txts[] = $stem.$ed;
						$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
					}
				} else {
					$txts[] = $stem.$ending;
					$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
				}
			}
			$vtab = $vtab."</td>";
		}
		$vtab = $vtab."</tr>\n";
	}

}
?>

<script type="text/javascript">
function check() 
{

<?php
	for($i = 0, $nall = count($txts); $i < $nall; $i++) {
		print "if (document.n01.text".$i.".value=='".$txts[$i]."')\n{\n";
		print "\tdocument.n01.text".$i.".disabled=true;\n}\n";
	}
?>

}

function newWord() 
{
<?php
	for($i = 0, $nall = count($txts); $i < $nall; $i++) {
		print "document.n01.text".$i.".disabled=false;\n";
 		print "document.n01.text".$i.".value='';\n";
	}
?>
	location.reload();
}
</script>

<body>

<div id="container">
<div id="center">
<form name="n01" action="">
<table align="center">
<?php
	print $vtab;
?>
<tr><td></td>
	<td align="center" colspan=<?php echo $n; ?>><input name="Check" onclick="check()" value="Check" type="button"></td>
	<td align="center" colspan=<?php echo $n; ?>><input name="New Word" onclick="newWord()" value="New Word" type="button"></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
